<admintpl file="header" />
<link rel="stylesheet" href="css/index.css">
<style>
	input{
		margin-top:10px;
	}
</style>
</head>
<body>
	<div class="wrap">
		<form method="post" class="form-horizontal" id="pub_form" action="{:U('Admin/Guest/add_answer')}"
			  enctype="multipart/form-data">
				<div class="control-group">
					<label class="span1 control-label" style="width: 90px;">竞猜题目：</label>
					<div class="span3">
						<input type="text" name="task_name"  style="width: 556px;" value="{$quiz_info.quiz_name}">
					</div>
				</div>
				<div class="control-group">
					<label class="span1 control-label" style="width: 90px;">设置题目答案：</label>
					<?php
					if(!empty($answer)){
					?>
					<foreach name="answer" item="vo" key="keys">
						<if condition="$keys eq 0">
							<div id="InputsWrapper" class="span3">
								<div><input type="text" name="answer[]" id="field_1" value="{$vo.rule_name}" placeholder="请输入答案"/></div>
							</div>
							<a href="#" id="AddMoreFileBox"><input type="button" id="b" value="添加" style="margin-left: 10px; margin-top: 15px;"/></a></span></p>
							<else/>
							<label class="span1 control-label" style="width: 90px;"></label>
							<div style="width: 400px;" class="span3" id="InputsWrapper"><input type="text" placeholder="请输入答案" name="answer[]" id="field_'+ FieldCount +'" value="{$vo.rule_name}"/><a href="#" class="removeclass" style="margin-left: 10px;">删除</a></div>
						</if>
					</foreach>
					<?php
					}else{
					?>
					<div id="InputsWrapper" class="span3">
						<div><input type="text" name="answer[1]" id="field_1" value="{$vo.rule_name}" placeholder="请输入答案"/></div>
					</div>
					<a href="#" id="AddMoreFileBox"><input type="button" id="b" value="添加" style="margin-left: 10px; margin-top: 15px;"/></a></span></p>
					<?php
					}
					?>
				</div>
				<input type="hidden" name="id" value="{$id}">
				<input type="hidden" name="live_id" value="{$live_id}">
			<div class="form-actions" style="padding-left:260px;">
				<button type="button" id="quick_publish" class="btn">保存</button>
				&nbsp;&nbsp;
			</div>
		</form>
	</div>
	<script src="__PUBLIC__/js/common.js"></script>
	<script type="text/javascript" src="__PUBLIC__/js/content_addtop.js"></script>

</body>
</html>
<script>
	$(document).ready(function() {

		var MaxInputs       = 8; //maximum input boxes allowed
		var InputsWrapper   = $("#InputsWrapper"); //Input boxes wrapper ID
		var AddButton       = $("#AddMoreFileBox"); //Add button ID

		var x = InputsWrapper.length; //initlal text box count
		var FieldCount=1; //to keep track of text box added

		$(AddButton).click(function (e)  //on add input button click
		{
			if(x <= MaxInputs) //max input box allowed
			{
				FieldCount++; //text box added increment
				//add input box
				$(InputsWrapper).append('<div style="width: 400px;"><input type="text" placeholder="请输入答案" name="answer['+FieldCount+']" id="field_'+ FieldCount +'" value=""/><a href="#" class="removeclass" style="margin-left: 10px;">删除</a></div>');
				x++; //text box increment
			}
			return false;
		});

		$("body").on("click",".removeclass", function(e){ //user click on remove text
			if( x >= 1 ) {
				$(this).parent('div').remove(); //remove text box
				x--; //decrement textbox
			}
			return false;
		})

	});
</script>